dnl -*- mode: Autoconf; -*-

dnl -----------------------------------------------------------------------------------------
dnl check for boost headers and libraries
dnl -----------------------------------------------------------------------------------------

AC_MSG_NOTICE([--------------------------------------------------------------------------------])
AC_MSG_NOTICE([CHECKING FOR BOOST])
AC_MSG_NOTICE([--------------------------------------------------------------------------------])

AC_LANG(C++)
AC_LINK_IFELSE([AC_LANG_PROGRAM()]) # workaround for a bug in older autoconf

AX_BOOST_BASE([1.33])

if test "x$succeeded" != xyes;  then
  AC_MSG_ERROR([Please install at least version 1.33 from http://www.boost.org/])
else
  tr_BOOST="yes"
fi

dnl -----------------------------------------------------------------------------------------
dnl guess boost library suffix
dnl -----------------------------------------------------------------------------------------

BOOST_SUFFIX=""

case $target in
  *-apple-darwin*)
    BOOST_SUFFIX="-mt"
    ;;

  *)
    BOOST_SUFFIX=""
    ;;
esac

dnl -----------------------------------------------------------------------------------------
dnl fix include and static libraries
dnl -----------------------------------------------------------------------------------------

TR_INCLUDE([BOOST_CPPFLAGS])

dnl -----------------------------------------------------------------------------------------
dnl add substitutions
dnl -----------------------------------------------------------------------------------------

AC_SUBST(BOOST_CPPFLAGS)
AC_SUBST(BOOST_LDFLAGS)
AC_SUBST(BOOST_LIBS)

dnl -----------------------------------------------------------------------------------------
dnl save flags
dnl -----------------------------------------------------------------------------------------

SAVE_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"

SAVE_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"

dnl -----------------------------------------------------------------------------------------
dnl grep boost version number
dnl -----------------------------------------------------------------------------------------

cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <boost/version.hpp>

main () {
  long sdnhg36ed = BOOST_VERSION ;
}

_ACEOF
AC_MSG_CHECKING([BOOST version])
eval "$ac_cpp conftest.$ac_ext" | fgrep "long sdnhg36ed" | awk '{ma = int($4 / 100000); mi = int($4 / 100) % 100; pl = ($4 % 100); print ma "." mi "." pl}' > conftest.output
TRI_BOOST_VERSION=`cat conftest.output`
AC_MSG_RESULT([$TRI_BOOST_VERSION])
rm -f conftest*

dnl -----------------------------------------------------------------------------------------
dnl restore flags
dnl -----------------------------------------------------------------------------------------

LDFLAGS="$SAVE_LDFLAGS"
CPPFLAGS="$SAVE_CPPFLAGS"

BOOST_CPPFLAGS="${BOOST_CPPFLAGS} -DTRI_BOOST_VERSION='\"${TRI_BOOST_VERSION}\"'"

dnl -----------------------------------------------------------------------------------------
dnl informational output
dnl -----------------------------------------------------------------------------------------

LIB_INFO="$LIB_INFO|BOOST VERSION: $TRI_BOOST_VERSION"

FLAG_INFO="$FLAG_INFO|BOOST_CPPFLAGS: ${BOOST_CPPFLAGS}"
FLAG_INFO="$FLAG_INFO|BOOST_LDFLAGS:  ${BOOST_LDFLAGS}"
FLAG_INFO="$FLAG_INFO|BOOST_LIBS:     ${BOOST_LIBS}"
FLAG_INFO="$FLAG_INFO|."

dnl Local Variables:
dnl mode: outline-minor
dnl outline-regexp: "^\\(dnl --SECTION--\\)"
dnl End:
